package com.yangzb.java.sample.lock;

import java.util.concurrent.TimeUnit;

public class LockObject {
    private Object obj = new Object();
    public void test1(){
        synchronized (obj){
            for (int i = 0; i < 5; i++) {
                System.out.println("test1:"+obj);
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public void test2(){
        synchronized (obj){
            for (int i = 0; i < 5; i++) {
                System.out.println("test2:"+obj);
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
